@extends('layouts.main')

@section('title', '销售组织列表')

@section('content')
<h3>@yield('title')</h3>
<div class="btn-group" role="group">
  <a href="{{ action('BaseData\SalesOrganizationController@create') }}" class="btn btn-primary">添加销售组织</a>
</div>
<table class="table table-bordered table-striped table-hover">
  <tr>
    <th>id</td>
    <th>销售组织代码</td>
    <th>销售组织描述</td> 
    <th>操作</td>
  </tr>
  @forelse($models as $model)
  <tr>
    <td>{{ $model->id }}</td>
    <td>{{ $model->code }}</td>
    <td>{{ $model->code_desc }}</td>
    <td>
        <a href="{{ action('BaseData\SalesOrganizationController@edit', $model) }}" class="btn btn-warning btn-sm">编辑</a>
        <button name="delete" value="{{ $model->id }}" class="btn btn-danger btn-sm">删除</button>
    </td>
  </tr>
  @empty
  <tr><td>暂无数据</td></tr>
  @endforelse
</table>

<script>
      $(document).ready(function(){
        $("button[name=delete]").click(function(){
            var that = $(this);
            var id = that.attr("value");
            $.post("/base_data/sales_organization/" + id, {
                '_method': 'DELETE',
                '_token': '{{ csrf_token() }}',
            }, function(data){
                switch(data.status){
                    case 0:
                        that.parent().parent('tr').remove();
                        alert("删除信息成功！");
                        break;
                }
            });
        });
    });
</script>
@endsection